package com.tjetc.ioc.test;

import com.tjetc.ioc.entity.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author gaoyongxiang
 * @version v1.0
 * @date 2025/9/1
 */
public class _1TestSpring {
    public static void main1(String[] args) {
        // 1. 获取容器
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        // 2. 根据类型获取bean对象
        //Spring中bean中的id就是name
//        User user = context.getBean(User.class);
//        User user = (User) context.getBean("user", User.class);
//        System.out.println(user);
    }


    public static void main(String[] args) {

        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
//        System.out.println(1);
        //spring默认创建的bean对象是单例的
        User user1 = (User) context.getBean("com.tjetc.ioc.entity.User#1");
        User user = (User) context.getBean("com.tjetc.ioc.entity.User#1");
        System.out.println(user);
        System.out.println(user == user1);
    }

}